﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestBC25Module
{
    public partial class Form_Main : Form
    {
        /**
         * 中国电信 消费级物联网专用卡（NB 14100）
         * 最晚启用日期：2020/12/31
         * ICCID：8986 1119 2320 0474 056H Q
         * PUK：3586 2331
         * 
         * https://gitee.com/xuxingxing2020/TestBC25Module.git
         */
        private BC25 bC25;
        public Form_Main()
        {
            InitializeComponent();
            bC25 = new BC25(serialPort1, false, "COM1", "9600", "NONE");
            comboBox_init();

            Logger.Callback_ShowMessage = new delegate_ShowMessageToTextBox(AddToTextBoxMsg);
            bC25.Callback_Modify_textBox_ObjectId = new delegate_EventHandler_textBox_ObjectId(Modify_textBox_ObjectId);
            bC25.Callback_Modify_textBox_Revision = new delegate_EventHandler_textBox_Revision(Modify_textBox_Revision);
            bC25.Callback_Modify_textBox_ObjectId2 = new delegate_EventHandler_textBox_ObjectId2(Modify_textBox_ObjectId2);
            bC25.Callback_Modify_textBox_Revision2 = new delegate_EventHandler_textBox_Revision2(Modify_textBox_Revision2);
            bC25.Callback_Modify_textBox_ObjectId3 = new delegate_EventHandler_textBox_ObjectId3(Modify_textBox_ObjectId3);
            bC25.Callback_Modify_textBox_Revision3 = new delegate_EventHandler_textBox_Revision3(Modify_textBox_Revision3);
            bC25.Callback_Modify_textBox_CMEE1 = new delegate_EventHandler_textBox_CMEE1(Modify_textBox_CMEE1);
            bC25.Callback_Modify_textBox_CMEE2 = new delegate_EventHandler_textBox_CMEE2(Modify_textBox_CMEE2);
            bC25.Callback_Modify_textBox_CGSN1 = new delegate_EventHandler_textBox_CGSN1(Modify_textBox_CGSN1);
            bC25.Callback_Modify_textBox_CGSN3 = new delegate_EventHandler_textBox_CGSN3(Modify_textBox_CGSN3);
            bC25.Callback_Modify_textBox_IPR1 = new delegate_EventHandler_textBox_IPR1(Modify_textBox_IPR1);
            bC25.Callback_Modify_textBox_IPR2 = new delegate_EventHandler_textBox_IPR2(Modify_textBox_IPR2);
            bC25.Callback_Modify_textBox_QEAUART1 = new delegate_EventHandler_textBox_QEAUART1(Modify_textBox_QEAUART1);
            bC25.Callback_Modify_textBox_QEAUART2 = new delegate_EventHandler_textBox_QEAUART2(Modify_textBox_QEAUART2);
            bC25.Callback_Modify_textBox_CPIN_code = new delegate_EventHandler_textBox_CPIN_code(Modify_textBox_CPIN_code);
            bC25.Callback_Modify_textBox_CIMI = new delegate_EventHandler_textBox_CIMI(Modify_textBox_CIMI);
            bC25.Callback_Modify_textBox_QCCID = new delegate_EventHandler_textBox_QCCID(Modify_textBox_QCCID);
            bC25.Callback_Modify_textBox_CSCON1 = new delegate_EventHandler_textBox_CSCON1(Modify_textBox_CSCON1);
            //textBox_Message.Size = (792, 223);
            //textBox_Message.Location = (5, 224);
        }

        private void comboBox_init()
        {
            comboBox_BaudRate.Items.Add("1200");
            comboBox_BaudRate.Items.Add("2400");
            comboBox_BaudRate.Items.Add("4800");
            comboBox_BaudRate.Items.Add("9600");
            comboBox_BaudRate.Items.Add("14400");
            comboBox_BaudRate.Items.Add("19200");
            comboBox_BaudRate.Items.Add("28800");
            comboBox_BaudRate.Items.Add("38400");
            comboBox_BaudRate.Items.Add("57600");
            comboBox_BaudRate.SelectedIndex = 3;

            comboBox_Parity.Items.Add("NONE");
            comboBox_Parity.SelectedIndex = 0;

            comboBox_EchoMode.Items.Add("0.關閉回顯");
            comboBox_EchoMode.Items.Add("1.開啟回顯");
            comboBox_EchoMode.SelectedIndex = 0;

            comboBox_InitNum.Items.Add("配置文件編號=0");
            comboBox_InitNum.SelectedIndex = 0;

            comboBox_CGSN.Items.Add("<snt>=0,sn");
            comboBox_CGSN.Items.Add("<snt>=1,imei");
            comboBox_CGSN.SelectedIndex = 0;

            comboBox_CMEE.Items.Add("0.禁用結果碼");
            comboBox_CMEE.Items.Add("1.啟用結果碼，為數值格式");
            comboBox_CMEE.Items.Add("2.啟用結果碼，為詳細錯誤信息");
            comboBox_CMEE.SelectedIndex = 0;

            comboBox_IPR.Items.Add("2400");
            comboBox_IPR.Items.Add("4800");
            comboBox_IPR.Items.Add("9600");
            comboBox_IPR.Items.Add("14400");
            comboBox_IPR.Items.Add("19200");
            comboBox_IPR.Items.Add("28800");
            comboBox_IPR.Items.Add("33600");
            comboBox_IPR.Items.Add("38400");
            comboBox_IPR.Items.Add("57600");
            comboBox_IPR.SelectedIndex = 2;

            comboBox_QEAUART_mode.Items.Add("0.關閉雙串口功能");
            comboBox_QEAUART_mode.Items.Add("1.開啟雙串口功能");
            comboBox_QEAUART_mode.SelectedIndex = 0;

            comboBox_QEAUART_rate.Items.Add("1200");
            comboBox_QEAUART_rate.Items.Add("2400");
            comboBox_QEAUART_rate.Items.Add("4800");
            comboBox_QEAUART_rate.Items.Add("9600");
            comboBox_QEAUART_rate.Items.Add("14400");
            comboBox_QEAUART_rate.Items.Add("19200");
            comboBox_QEAUART_rate.Items.Add("28800");
            comboBox_QEAUART_rate.Items.Add("38400");
            comboBox_QEAUART_rate.Items.Add("57600");
            comboBox_QEAUART_rate.SelectedIndex = 3;

            comboBox_QEAUART_data.Items.Add("5");
            comboBox_QEAUART_data.Items.Add("6");
            comboBox_QEAUART_data.Items.Add("7");
            comboBox_QEAUART_data.Items.Add("8");
            comboBox_QEAUART_data.SelectedIndex = 3;

            comboBox_QEAUART_stop.Items.Add("1");
            comboBox_QEAUART_stop.Items.Add("2");
            comboBox_QEAUART_stop.Items.Add("3");
            comboBox_QEAUART_stop.SelectedIndex = 0;

            comboBox_QEAUART_parity.Items.Add("0.None");
            comboBox_QEAUART_parity.Items.Add("1.Odd");
            comboBox_QEAUART_parity.Items.Add("2.Even");
            comboBox_QEAUART_parity.Items.Add("3.Mark");
            comboBox_QEAUART_parity.SelectedIndex = 0;

            comboBox_CSQ.Items.Add("=?測試");
            comboBox_CSQ.Items.Add("執行");
            comboBox_CSQ.SelectedIndex = 0;

            comboBox_CESQ.Items.Add("=?測試");
            comboBox_CESQ.Items.Add("執行");
            comboBox_CESQ.SelectedIndex = 0;

            comboBox_CEREG1.Items.Add("=?測試");
            comboBox_CEREG1.Items.Add("?查詢");
            comboBox_CEREG1.Items.Add("=設置");
            comboBox_CEREG1.SelectedIndex = 0;

            comboBox_CGATT.Items.Add("=?測試");
            comboBox_CGATT.Items.Add("?查詢");
            comboBox_CGATT.Items.Add("=0設置去附著");
            comboBox_CGATT.Items.Add("=1設置附著");
            comboBox_CGATT.SelectedIndex = 0;

            comboBox_QCGDEFCONT1.Items.Add("=?測試");
            comboBox_QCGDEFCONT1.Items.Add("?查詢");
            comboBox_QCGDEFCONT1.Items.Add("=設置");
            comboBox_QCGDEFCONT1.SelectedIndex = 0;

            comboBox_QCGDEFCONT2.Items.Add("IP 互聯網協議(IETF STD 5)");
            comboBox_QCGDEFCONT2.Items.Add("IPV6 互聯網協議版本6(IETF RFC 2460)");
            comboBox_QCGDEFCONT2.Items.Add("IPV4V6 雙棧，UE能力");
            comboBox_QCGDEFCONT2.Items.Add("Non-IP 無IP數據到外部分組網絡的傳輸");
            comboBox_QCGDEFCONT2.SelectedIndex = 2;

            comboBox_CGDCONT1.Items.Add("=?測試");
            comboBox_CGDCONT1.Items.Add("?查詢");
            comboBox_CGDCONT1.Items.Add("=設置");
            comboBox_CGDCONT1.SelectedIndex = 0;

            comboBox_CGDCONT2.Items.Add("IP 互聯網協議(IETF STD 5 [103])");
            comboBox_CGDCONT2.Items.Add("IPV6 互聯網協議版本6");
            comboBox_CGDCONT2.Items.Add("IPV4V6 引入虛擬<PDP_type>處理IP雙棧UE功能");
            comboBox_CGDCONT2.Items.Add("Non-IP 無IP");
            comboBox_CGDCONT2.SelectedIndex = 2;

            comboBox_CGDCONT3.Items.Add("0.關閉");
            comboBox_CGDCONT3.Items.Add("1.開啟");
            comboBox_CGDCONT3.Items.Add("2.V.42bis");
            comboBox_CGDCONT3.Items.Add("3.V.44bis");
            comboBox_CGDCONT3.SelectedIndex = 0;

            comboBox_CGDCONT4.Items.Add("0.關閉");
            comboBox_CGDCONT4.Items.Add("1.開啟");
            comboBox_CGDCONT4.Items.Add("2.RFC1144(僅適用於SNDCP)");
            comboBox_CGDCONT4.Items.Add("3.RFC2507");
            comboBox_CGDCONT4.Items.Add("4.RFC3095[ROHC](僅適用於PDCP)");
            comboBox_CGDCONT4.SelectedIndex = 0;

            comboBox_CGACT1.Items.Add("=?測試");
            comboBox_CGACT1.Items.Add("?查詢");
            comboBox_CGACT1.Items.Add("=設置");
            comboBox_CGACT1.SelectedIndex = 0;

            comboBox_CGACT2.Items.Add("0.去激活(停用)");
            comboBox_CGACT2.Items.Add("1.激活");
            comboBox_CGACT2.SelectedIndex = 0;

            comboBox_CGACT3.Items.Add("1.PDP上下文的標識符");
            comboBox_CGACT3.Items.Add("2.PDP上下文的標識符");
            comboBox_CGACT3.Items.Add("3.PDP上下文的標識符");
            comboBox_CGACT3.Items.Add("4.PDP上下文的標識符");
            comboBox_CGACT3.Items.Add("5.PDP上下文的標識符");
            comboBox_CGACT3.Items.Add("6.PDP上下文的標識符");
            comboBox_CGACT3.Items.Add("7.PDP上下文的標識符");
            comboBox_CGACT3.SelectedIndex = 0;

            comboBox_CGPADDR1.Items.Add("=?測試");
            comboBox_CGPADDR1.Items.Add("?查詢");
            comboBox_CGPADDR1.Items.Add("=設置");
            comboBox_CGPADDR1.Items.Add("執行");
            comboBox_CGPADDR1.SelectedIndex = 0;

            comboBox_CGPADDR2.Items.Add("1.PDP上下文的標識符");
            comboBox_CGPADDR2.Items.Add("2.PDP上下文的標識符");
            comboBox_CGPADDR2.Items.Add("3.PDP上下文的標識符");
            comboBox_CGPADDR2.Items.Add("4.PDP上下文的標識符");
            comboBox_CGPADDR2.Items.Add("5.PDP上下文的標識符");
            comboBox_CGPADDR2.Items.Add("6.PDP上下文的標識符");
            comboBox_CGPADDR2.Items.Add("7.PDP上下文的標識符");
            comboBox_CGPADDR2.SelectedIndex = 0;

            comboBox_CGPADDR3.Items.Add("1.PDP上下文的標識符");
            comboBox_CGPADDR3.Items.Add("2.PDP上下文的標識符");
            comboBox_CGPADDR3.Items.Add("3.PDP上下文的標識符");
            comboBox_CGPADDR3.Items.Add("4.PDP上下文的標識符");
            comboBox_CGPADDR3.Items.Add("5.PDP上下文的標識符");
            comboBox_CGPADDR3.Items.Add("6.PDP上下文的標識符");
            comboBox_CGPADDR3.Items.Add("7.PDP上下文的標識符");
            comboBox_CGPADDR3.SelectedIndex = 0;

            comboBox_CSCON1.Items.Add("=?測試");
            comboBox_CSCON1.Items.Add("?查詢");
            comboBox_CSCON1.Items.Add("=設置");
            comboBox_CSCON1.SelectedIndex = 0;

            comboBox_CSCON2.Items.Add("0.禁用URC");
            comboBox_CSCON2.Items.Add("1.使能URC");
            comboBox_CSCON2.SelectedIndex = 0;

            comboBox_COPS1.Items.Add("=?測試");
            comboBox_COPS1.Items.Add("?查詢");
            comboBox_COPS1.Items.Add("=設置");
            comboBox_COPS1.SelectedIndex = 0;

            comboBox_COPS2.Items.Add("0.自動模式（省略<format>、<oper>和<AcT>字段）");
            comboBox_COPS2.Items.Add("1.手動模式（包含<format>和<oper>字段，<AcT>可選）");
            comboBox_COPS2.Items.Add("2.手動註銷網絡");
            comboBox_COPS2.Items.Add("3.僅設置<format>（將不在查詢命令AT+COPS?響應中返回）");
            comboBox_COPS2.Items.Add("4.手動/自動選擇。如果手動選擇失敗，則進入自動模式<mode>=0");
            comboBox_COPS2.SelectedIndex = 0;

            comboBox_COPS3.Items.Add("0.長字符");
            comboBox_COPS3.Items.Add("1.短字符");
            comboBox_COPS3.Items.Add("2.數字");
            comboBox_COPS3.SelectedIndex = 2;

            comboBox_COPS4.Items.Add("7.E-UTRAN");
            comboBox_COPS4.Items.Add("9.E-UTRAN(NB-S1模式)");
            comboBox_COPS4.SelectedIndex = 0;

            comboBox_CPSMS1.Items.Add("=?測試");
            comboBox_CPSMS1.Items.Add("?查詢");
            comboBox_CPSMS1.Items.Add("=設置");
            comboBox_CPSMS1.SelectedIndex = 0;

            comboBox_CPSMS2.Items.Add("0.禁用PSM");
            comboBox_CPSMS2.Items.Add("1.啟用PSM");
            comboBox_CPSMS2.Items.Add("2.禁用PSM併刪除PSM的所有參數，恢復默認值");
            comboBox_CPSMS2.SelectedIndex = 1;

            comboBox_CPSMS3.Items.Add("000.倍數為10分鐘");
            comboBox_CPSMS3.Items.Add("001.倍數為1小時");
            comboBox_CPSMS3.Items.Add("010.倍數為10小時");
            comboBox_CPSMS3.Items.Add("011.倍數為2秒");
            comboBox_CPSMS3.Items.Add("100.倍數為30秒");
            comboBox_CPSMS3.Items.Add("101.倍數為1分鐘");
            comboBox_CPSMS3.Items.Add("110.倍數為320小時");
            comboBox_CPSMS3.Items.Add("111.定時器被停用");
            comboBox_CPSMS3.SelectedIndex = 0;

            comboBox_CPSMS4.Items.Add("000.倍數為2秒");
            comboBox_CPSMS4.Items.Add("001.倍數為1分鐘");
            comboBox_CPSMS4.Items.Add("010.倍數為6分鐘");
            comboBox_CPSMS4.Items.Add("111.定時器被停用");
            comboBox_CPSMS4.SelectedIndex = 0;
        }

        public delegate void delegate_ShowMessageToTextBox(string msg);
        private void AddToTextBoxMsg(string s)
        {
            try
            {
                if (textBox_Message != null && !textBox_Message.IsDisposed)
                {
                    if (textBox_Message.InvokeRequired)
                    {
                        delegate_ShowMessageToTextBox d = AddToTextBoxMsg;
                        textBox_Message.Invoke(d, s);
                    }
                    else
                    {
                        textBox_Message.AppendText(s);
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_ObjectId(string str);
        private void Modify_textBox_ObjectId(string s)
        {
            try
            {
                if (textBox_ObjectId != null && !textBox_ObjectId.IsDisposed)
                {
                    if (textBox_ObjectId.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_ObjectId d = Modify_textBox_ObjectId;
                        textBox_ObjectId.Invoke(d, s);
                    }
                    else
                    {
                        textBox_ObjectId.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
            
        }

        public delegate void delegate_EventHandler_textBox_Revision(string str);
        private void Modify_textBox_Revision(string s)
        {
            try
            {
                if (textBox_Revision != null && !textBox_Revision.IsDisposed)
                {
                    if (textBox_Revision.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_Revision d = Modify_textBox_Revision;
                        textBox_Revision.Invoke(d, s);
                    }
                    else
                    {
                        textBox_Revision.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_ObjectId2(string str);
        private void Modify_textBox_ObjectId2(string s)
        {
            try
            {
                if (textBox_ObjectId2 != null && !textBox_ObjectId2.IsDisposed)
                {
                    if (textBox_ObjectId2.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_ObjectId2 d = Modify_textBox_ObjectId2;
                        textBox_ObjectId2.Invoke(d, s);
                    }
                    else
                    {
                        textBox_ObjectId2.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }

        }

        public delegate void delegate_EventHandler_textBox_Revision2(string str);
        private void Modify_textBox_Revision2(string s)
        {
            try
            {
                if (textBox_Revision2 != null && !textBox_Revision2.IsDisposed)
                {
                    if (textBox_Revision2.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_Revision2 d = Modify_textBox_Revision2;
                        textBox_Revision2.Invoke(d, s);
                    }
                    else
                    {
                        textBox_Revision2.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_ObjectId3(string str);
        private void Modify_textBox_ObjectId3(string s)
        {
            try
            {
                if (textBox_ObjectId3 != null && !textBox_ObjectId3.IsDisposed)
                {
                    if (textBox_ObjectId3.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_ObjectId3 d = Modify_textBox_ObjectId3;
                        textBox_ObjectId3.Invoke(d, s);
                    }
                    else
                    {
                        textBox_ObjectId3.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_Revision3(string str);
        private void Modify_textBox_Revision3(string s)
        {
            try
            {
                if (textBox_Revision3 != null && !textBox_Revision3.IsDisposed)
                {
                    if (textBox_Revision3.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_Revision3 d = Modify_textBox_Revision3;
                        textBox_Revision3.Invoke(d, s);
                    }
                    else
                    {
                        textBox_Revision3.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_CMEE1(string str);
        private void Modify_textBox_CMEE1(string s)
        {
            try
            {
                if (textBox_CMEE1 != null && !textBox_CMEE1.IsDisposed)
                {
                    if (textBox_CMEE1.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_CMEE1 d = Modify_textBox_CMEE1;
                        textBox_CMEE1.Invoke(d, s);
                    }
                    else
                    {
                        textBox_CMEE1.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_CMEE2(string str);
        private void Modify_textBox_CMEE2(string s)
        {
            try
            {
                if (textBox_CMEE2 != null && !textBox_CMEE2.IsDisposed)
                {
                    if (textBox_CMEE2.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_CMEE2 d = Modify_textBox_CMEE2;
                        textBox_CMEE2.Invoke(d, s);
                    }
                    else
                    {
                        textBox_CMEE2.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_CGSN1(string str);
        private void Modify_textBox_CGSN1(string s)
        {
            try
            {
                if (textBox_CGSN1 != null && !textBox_CGSN1.IsDisposed)
                {
                    if (textBox_CGSN1.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_CGSN1 d = Modify_textBox_CGSN1;
                        textBox_CGSN1.Invoke(d, s);
                    }
                    else
                    {
                        textBox_CGSN1.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_CGSN3(string str);
        private void Modify_textBox_CGSN3(string s)
        {
            try
            {
                if (textBox_CGSN3 != null && !textBox_CGSN3.IsDisposed)
                {
                    if (textBox_CGSN3.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_CGSN3 d = Modify_textBox_CGSN3;
                        textBox_CGSN3.Invoke(d, s);
                    }
                    else
                    {
                        textBox_CGSN3.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_IPR1(string str);
        private void Modify_textBox_IPR1(string s)
        {
            try
            {
                if (textBox_IPR1 != null && !textBox_IPR1.IsDisposed)
                {
                    if (textBox_IPR1.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_IPR1 d = Modify_textBox_IPR1;
                        textBox_IPR1.Invoke(d, s);
                    }
                    else
                    {
                        textBox_IPR1.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_IPR2(string str);
        private void Modify_textBox_IPR2(string s)
        {
            try
            {
                if (textBox_IPR2 != null && !textBox_IPR2.IsDisposed)
                {
                    if (textBox_IPR2.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_IPR2 d = Modify_textBox_IPR2;
                        textBox_IPR2.Invoke(d, s);
                    }
                    else
                    {
                        textBox_IPR2.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_QEAUART1(string str);
        private void Modify_textBox_QEAUART1(string s)
        {
            try
            {
                if (textBox_QEAUART1 != null && !textBox_QEAUART1.IsDisposed)
                {
                    if (textBox_QEAUART1.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_QEAUART1 d = Modify_textBox_QEAUART1;
                        textBox_QEAUART1.Invoke(d, s);
                    }
                    else
                    {
                        textBox_QEAUART1.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_QEAUART2(string str);
        private void Modify_textBox_QEAUART2(string s)
        {
            try
            {
                if (textBox_QEAUART2 != null && !textBox_QEAUART2.IsDisposed)
                {
                    if (textBox_QEAUART2.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_QEAUART2 d = Modify_textBox_QEAUART2;
                        textBox_QEAUART2.Invoke(d, s);
                    }
                    else
                    {
                        textBox_QEAUART2.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_CPIN_code(string str);
        private void Modify_textBox_CPIN_code(string s)
        {
            try
            {
                if (textBox_CPIN_code != null && !textBox_CPIN_code.IsDisposed)
                {
                    if (textBox_CPIN_code.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_CPIN_code d = Modify_textBox_CPIN_code;
                        textBox_CPIN_code.Invoke(d, s);
                    }
                    else
                    {
                        textBox_CPIN_code.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_CIMI(string str);
        private void Modify_textBox_CIMI(string s)
        {
            try
            {
                if (textBox_CIMI != null && !textBox_CIMI.IsDisposed)
                {
                    if (textBox_CIMI.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_CIMI d = Modify_textBox_CIMI;
                        textBox_CIMI.Invoke(d, s);
                    }
                    else
                    {
                        textBox_CIMI.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_QCCID(string str);
        private void Modify_textBox_QCCID(string s)
        {
            try
            {
                if (textBox_QCCID != null && !textBox_QCCID.IsDisposed)
                {
                    if (textBox_QCCID.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_QCCID d = Modify_textBox_QCCID;
                        textBox_QCCID.Invoke(d, s);
                    }
                    else
                    {
                        textBox_QCCID.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        public delegate void delegate_EventHandler_textBox_CSCON1(string str);
        private void Modify_textBox_CSCON1(string s)
        {
            try
            {
                if (textBox_CSCON1 != null && !textBox_CSCON1.IsDisposed)
                {
                    if (textBox_CSCON1.InvokeRequired)
                    {
                        delegate_EventHandler_textBox_CSCON1 d = Modify_textBox_CSCON1;
                        textBox_CSCON1.Invoke(d, s);
                    }
                    else
                    {
                        textBox_CSCON1.Text = s;
                    }
                }
            }
            catch (Exception unerr) { Console.WriteLine(unerr); }
        }

        private void button_OpenCom_Click(object sender, EventArgs e)//打开串口
        {
            if (serialPort1.IsOpen)//判断串口是否已经被打开了
            {
                label_ComStatus.Text = "串口已打開";
                label_ComStatus.ForeColor = Color.Green;
            }
            else
            {
                bC25.ComNameStr = textBox_ComName.Text;
                bC25.BaudRateStr = comboBox_BaudRate.SelectedItem.ToString();
                bC25.ParityStr = comboBox_Parity.SelectedItem.ToString();

                bC25.EnableFlag = true;
                bC25.OpenCom();
                if (serialPort1.IsOpen)//判断串口是否已经被打开了
                {
                    label_ComStatus.Text = "串口打開成功";
                    label_ComStatus.ForeColor = Color.Green;
                    button_OpenCom.Enabled = false;
                    button_OpenCom.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.Control);
                    button_CloseCom.Enabled = true;
                    button_CloseCom.BackColor = Color.Red;
                }
                else
                {
                    label_ComStatus.Text = "串口打開失敗";
                    label_ComStatus.ForeColor = Color.Red;
                }
            }
        }

        private void button_CloseCom_Click(object sender, EventArgs e)//关闭串口
        {
            if (serialPort1.IsOpen)//判断串口是否已经被打开了
            {
                bC25.CloseCom();
                if (serialPort1.IsOpen)//判断串口是否已经被打开了
                {
                    label_ComStatus.Text = "串口關閉失敗";
                    label_ComStatus.ForeColor = Color.Red;
                }
                else
                {
                    bC25.EnableFlag = false;
                    label_ComStatus.Text = "串口關閉成功";
                    label_ComStatus.ForeColor = Color.Red;
                    button_OpenCom.Enabled = true;
                    button_OpenCom.BackColor = Color.Green;
                    button_CloseCom.Enabled = false;
                    button_CloseCom.BackColor = Color.FromKnownColor(System.Drawing.KnownColor.Control);
                }
            }
            else
            {
                label_ComStatus.Text = "串口已關閉";
                label_ComStatus.ForeColor = Color.Red;
            }
        }

        private void button_ATI_Click(object sender, EventArgs e)//ATI显示产品标识信息
        {
            bC25.encode("ATI", "ATI\r", 300);
        }

        private void button_ATE_Click(object sender, EventArgs e)//ATE设置命令的回显模式
        {
            bC25.encode("ATE", "ATE" + comboBox_EchoMode.SelectedIndex.ToString() + "\r", 300);
        }

        private void button_ATW_Click(object sender, EventArgs e)//AT&W 储存当前参数到用户定义的配置文件
        {
            bC25.encode("AT&W", "AT&W" + comboBox_InitNum.SelectedIndex.ToString() + "\r", 300);
        }

        private void button_CGMI_Click(object sender, EventArgs e)//AT+CGMI 请求制造商标识
        {
            if (checkBox_CGMI.Checked)
            {
                bC25.encode("AT+CGMI", "AT+CGMI=?\r", 300);
            }
            else
            {
                bC25.encode("AT+CGMI", "AT+CGMI\r", 300);
            }
        }

        private void button_CGMM_Click(object sender, EventArgs e)//AT+CGMM 请求模块标识
        {
            if (checkBox_CGMM.Checked)
            {
                bC25.encode("AT+CGMM", "AT+CGMM=?\r", 300);
            }
            else
            {
                bC25.encode("AT+CGMM", "AT+CGMM\r", 300);
            }
        }

        private void button_CGMR_Click(object sender, EventArgs e)//AT+CGMR 请求制造商版本号
        {
            if (checkBox_CGMR.Checked)
            {
                bC25.encode("AT+CGMR", "AT+CGMR=?\r", 300);
            }
            else
            {
                bC25.encode("AT+CGMR", "AT+CGMR\r", 300);
            }
        }

        private void button_CGSN_Click(object sender, EventArgs e)//AT+CGSN 请求产品序列号
        {
            if (radioButton_CGSN1.Checked)
            {
                bC25.encode("AT+CGSN", "AT+CGSN=?\r", 300);
            }
            else if (radioButton_CGSN2.Checked)
            {
                bC25.encode("AT+CGSN", "AT+CGSN=" + comboBox_CGSN.SelectedIndex.ToString() + "\r", 300);
            }
            else
            {
                bC25.encode("AT+CGSN", "AT+CGSN\r", 300);
            }
        }

        private void button_CMEE_Click(object sender, EventArgs e)//AT+CMEE 设置错误码上报
        {
            if (radioButton_CMEE1.Checked)
            {
                bC25.encode("AT+CMEE", "AT+CMEE?\r", 300);
            }
            else if (radioButton_CMEE2.Checked)
            {
                bC25.encode("AT+CMEE", "AT+CMEE=?\r", 300);
            }
            else
            {
                bC25.encode("AT+CMEE", "AT+CMEE=" + comboBox_CMEE.SelectedIndex.ToString() + "\r", 300);
            }
        }

        private void button_IPR_Click(object sender, EventArgs e)//AT+IPR 设置 TE-TA 固定的本地波特率
        {
            int i;
            if (radioButton_IPR1.Checked)
            {
                bC25.encode("AT+IPR", "AT+IPR=?\r", 300);
            }
            else if (radioButton_IPR2.Checked)
            {
                bC25.encode("AT+IPR", "AT+IPR?\r", 300);
            }
            else
            {
                bC25.encode("AT+IPR", "AT+IPR=" + comboBox_IPR.SelectedText + "\r", 300);
            }
        }

        private void button_QEAUART_Click(object sender, EventArgs e)//AT+QEAUART* 设置双串口功能
        {
            if (radioButton_QEAUART1.Checked)
            {
                bC25.encode("AT+QEAUART", "AT+QEAUART=?\r", 300);
            }
            else if (radioButton_QEAUART2.Checked)
            {
                bC25.encode("AT+QEAUART", "AT+QEAUART?\r", 300);
            }
            else
            {
                if (comboBox_QEAUART_mode.SelectedIndex == 0)
                {
                    bC25.encode("AT+QEAUART", "AT+QEAUART=0\r", 300);
                }
                else
                {
                    string param = "AT+QEAUART=1";
                    param += "," + comboBox_QEAUART_rate.SelectedText;
                    param += "," + comboBox_QEAUART_data.SelectedText;
                    param += "," + comboBox_QEAUART_stop.SelectedText;
                    param += "," + comboBox_QEAUART_parity.SelectedIndex.ToString();
                    bC25.encode("AT+QEAUART", param + "\r", 300);
                }
            }
        }

        private void button_CPIN_Click(object sender, EventArgs e)//AT+CPIN 输入 PIN 码
        {
            if (radioButton_CPIN1.Checked)
            {
                bC25.encode("AT+CPIN", "AT+CPIN=?\r", 5000);
            }
            else if (radioButton_CPIN2.Checked)
            {
                bC25.encode("AT+CPIN", "AT+CPIN?\r", 5000);
            }
            else
            {
                string param = "AT+CPIN=" + textBox_CPIN_pin.Text;
                if (textBox_CPIN_new.Text.Length != 0)
                {
                    param += "," + textBox_CPIN_new.Text;
                }
                bC25.encode("AT+CPIN", param + "\r", 5000);
            }
        }

        private void button_CIMI_Click(object sender, EventArgs e)//AT+CIMI 查询国际移动用户识别码
        {
            if (radioButton_CIMI1.Checked)
            {
                bC25.encode("AT+CIMI", "AT+CIMI=?\r", 600);
            }
            else
            {
                bC25.encode("AT+CIMI", "AT+CIMI\r", 600);
            }
        }

        private void button_QCCID_Click(object sender, EventArgs e)//AT+QCCID USIM 卡识别
        {
            bC25.encode("AT+QCCID", "AT+QCCID\r", 300);
        }

        private void button_CSQ_Click(object sender, EventArgs e)//AT+CSQ 上报信号质量
        {
            if(comboBox_CSQ.SelectedIndex == 0)
            {
                bC25.encode("AT+CSQ", "AT+CSQ=?\r", 300);
            }
            else
            {
                bC25.encode("AT+CSQ", "AT+CSQ\r", 300);
            }
            
        }

        private void button_CESQ_Click(object sender, EventArgs e)//AT+CESQ 扩展信号质量
        {
            if (comboBox_CESQ.SelectedIndex == 0)
            {
                bC25.encode("AT+CESQ", "AT+CESQ=?\r", 300);
            }
            else
            {
                bC25.encode("AT+CESQ", "AT+CESQ\r", 300);
            }
        }

        private void button_CEREG_Click(object sender, EventArgs e)//AT+CEREG EPS 网络注册状态
        {
            if (comboBox_CEREG1.SelectedIndex == 0)
            {
                bC25.encode("AT+CEREG", "AT+CEREG=?\r", 300);
            }
            else if (comboBox_CEREG1.SelectedIndex == 1)
            {
                bC25.encode("AT+CEREG", "AT+CEREG?\r", 300);
            }
            else
            {
                if (radioButton_CEREG0.Checked)
                {
                    bC25.encode("AT+CEREG", "AT+CEREG=0\r", 300);
                }
                else if (radioButton_CEREG1.Checked)
                {
                    bC25.encode("AT+CEREG", "AT+CEREG=1\r", 300);
                }
                else if (radioButton_CEREG2.Checked)
                {
                    bC25.encode("AT+CEREG", "AT+CEREG=2\r", 300);
                }
                else if (radioButton_CEREG3.Checked)
                {
                    bC25.encode("AT+CEREG", "AT+CEREG=3\r", 300);
                }
                else if (radioButton_CEREG4.Checked)
                {
                    bC25.encode("AT+CEREG", "AT+CEREG=4\r", 300);
                }
                else if (radioButton_CEREG5.Checked)
                {
                    bC25.encode("AT+CEREG", "AT+CEREG=5\r", 300);
                }
            }
        }

        private void button_CGATT_Click(object sender, EventArgs e)//AT+CGATT PS 附着与去附着
        {
            if (comboBox_CGATT.SelectedIndex == 0)
            {
                bC25.encode("AT+CGATT", "AT+CGATT=?\r", 300);
            }
            else if (comboBox_CGATT.SelectedIndex == 1)
            {
                bC25.encode("AT+CGATT", "AT+CGATT?\r", 300);
            }
            else if (comboBox_CGATT.SelectedIndex == 2)
            {
                bC25.encode("AT+CGATT", "AT+CGATT=0\r", 300);
            }
            else if (comboBox_CGATT.SelectedIndex == 3)
            {
                bC25.encode("AT+CGATT", "AT+CGATT=1\r", 300);
            }
        }

        private void button_QCGDEFCONT_Click(object sender, EventArgs e)//AT+QCGDEFCONT 设置默认 PDP 上下文
        {
            if (comboBox_QCGDEFCONT1.SelectedIndex == 0)
            {
                bC25.encode("AT+QCGDEFCONT", "AT+QCGDEFCONT=?\r", 300);
            }
            else if (comboBox_QCGDEFCONT1.SelectedIndex == 1)
            {
                bC25.encode("AT+QCGDEFCONT", "AT+QCGDEFCONT?\r", 300);
            }
            else
            {
                if (comboBox_QCGDEFCONT2.SelectedIndex == 0)
                {
                    bC25.encode("AT+QCGDEFCONT", "AT+QCGDEFCONT=IP\r", 300);
                }
                else if (comboBox_QCGDEFCONT2.SelectedIndex == 1)
                {
                    bC25.encode("AT+QCGDEFCONT", "AT+QCGDEFCONT=IPV6\r", 300);
                }
                else if (comboBox_QCGDEFCONT2.SelectedIndex == 2)
                {
                    bC25.encode("AT+QCGDEFCONT", "AT+QCGDEFCONT=IPV4V6\r", 300);
                }
                else
                {
                    bC25.encode("AT+QCGDEFCONT", "AT+QCGDEFCONT=Non-IP\r", 300);
                }
            }
        }

        private void button_CGDCONT_Click(object sender, EventArgs e)//AT+CGDCONT 定义 PDP 上下文
        {
            if (comboBox_CGDCONT1.SelectedIndex == 0)
            {
                bC25.encode("AT+CGDCONT", "AT+CGDCONT=?\r", 300);
            }
            else if (comboBox_CGDCONT1.SelectedIndex == 1)
            {
                bC25.encode("AT+CGDCONT", "AT+CGDCONT?\r", 300);
            }
            else
            {
                string str = "AT+CGDCONT=" + textBox_CGDCONT1.Text;
                if (comboBox_CGDCONT2.SelectedIndex == 0)
                {
                    str += ",IP";
                }
                else if (comboBox_CGDCONT2.SelectedIndex == 1)
                {
                    str += ",IPV6";
                }
                else if (comboBox_CGDCONT2.SelectedIndex == 2)
                {
                    str += ",IPV4V6";
                }
                else
                {
                    str += ",Non-IP";
                }
                str += "," + textBox_CGDCONT2.Text + "," + textBox_CGDCONT3.Text;
                str += "," + comboBox_CGDCONT3.SelectedIndex.ToString() + "," + comboBox_CGDCONT4.SelectedIndex.ToString() + "\r";
                bC25.encode("AT+CGDCONT", str, 300);
            }
        }

        private void button_CGACT_Click(object sender, EventArgs e)//AT+CGACT 激活或停用 PDP 上下文
        {
            if (comboBox_CGACT1.SelectedIndex == 0)
            {
                bC25.encode("AT+CGACT", "AT+CGACT=?\r", 150000);
            }
            else if (comboBox_CGACT1.SelectedIndex == 1)
            {
                bC25.encode("AT+CGACT", "AT+CGACT?\r", 150000);
            }
            else
            {
                bC25.encode("AT+CGACT", "AT+CGACT=" + comboBox_CGACT2.SelectedIndex.ToString() + "," +
                    (comboBox_CGACT3.SelectedIndex + 1).ToString() + "\r", 150000);
            }
        }

        private void button_CGPADDR_Click(object sender, EventArgs e)//AT+CGPADDR 显示 PDP 地址
        {
            if (comboBox_CGPADDR1.SelectedIndex == 0)
            {
                bC25.encode("AT+CGPADDR", "AT+CGPADDR=?\r", 300);
            }
            else if (comboBox_CGPADDR1.SelectedIndex == 1)
            {
                bC25.encode("AT+CGPADDR", "AT+CGPADDR?\r", 300);
            }
            else if (comboBox_CGPADDR1.SelectedIndex == 2)
            {
                bC25.encode("AT+CGPADDR", "AT+CGPADDR=" + 
                    (comboBox_CGPADDR2.SelectedIndex + 1) + "," + 
                    (comboBox_CGPADDR3.SelectedIndex + 1) + "\r", 300);
            }
            else
            {
                bC25.encode("AT+CGPADDR", "AT+CGPADDR\r", 300);
            }
        }

        private void button_CSCON_Click(object sender, EventArgs e)//AT+CSCON 信令连接状态
        {
            if (comboBox_CSCON1.SelectedIndex == 0)
            {
                bC25.encode("AT+CSCON", "AT+CSCON=?\r", 300);
            }
            else if (comboBox_CSCON1.SelectedIndex == 1)
            {
                bC25.encode("AT+CSCON", "AT+CSCON?\r", 300);
            }
            else
            {
                bC25.encode("AT+CSCON", "AT+CSCON=" + comboBox_CSCON2.SelectedIndex + "\r", 300);
            }
        }

        private void button_COPS_Click(object sender, EventArgs e)//AT+COPS 运营商选择
        {
            if (comboBox_COPS1.SelectedIndex == 0)
            {
                bC25.encode("AT+COPS", "AT+COPS=?\r", 630000);
            }
            else if (comboBox_COPS1.SelectedIndex == 1)
            {
                bC25.encode("AT+COPS", "AT+COPS?\r", 630000);
            }
            else
            {
                if (comboBox_COPS2.SelectedIndex == 0)
                {
                    bC25.encode("AT+COPS", "AT+COPS=" + comboBox_COPS2.SelectedIndex.ToString() + "\r", 630000);
                }
                else if (comboBox_COPS2.SelectedIndex == 1)
                {
                    int AcT_int;
                    if (comboBox_COPS4.SelectedIndex == 0)
                    {
                        AcT_int = 7;
                    }
                    else
                    {
                        AcT_int = 9;
                    }

                    bC25.encode("AT+COPS", "AT+COPS=1," + comboBox_COPS3.SelectedIndex.ToString() + "," + 
                        textBox_COPS.Text + "," + AcT_int + "\r", 630000);
                }
                else if (comboBox_COPS2.SelectedIndex == 2)
                {
                    bC25.encode("AT+COPS", "AT+COPS=" + comboBox_COPS2.SelectedIndex.ToString() + "\r", 630000);
                }
                else if (comboBox_COPS2.SelectedIndex == 3)
                {
                    bC25.encode("AT+COPS", "AT+COPS=" + comboBox_COPS2.SelectedIndex.ToString() + "\r", 630000);
                }
                else
                {
                    bC25.encode("AT+COPS", "AT+COPS=" + comboBox_COPS2.SelectedIndex.ToString() + "\r", 630000);
                }
            }
        }

        private void button_CPSMS_Click(object sender, EventArgs e)//AT+CPSMS 省电模式设置
        {
            if (comboBox_CPSMS1.SelectedIndex == 0)
            {
                bC25.encode("AT+CPSMS", "AT+CPSMS=?\r", 300);
            }
            else if (comboBox_CPSMS1.SelectedIndex == 1)
            {
                bC25.encode("AT+CPSMS", "AT+CPSMS?\r", 300);
            }
            else
            {
                if(comboBox_CPSMS2.SelectedIndex == 1)
                {
                    bC25.encode("AT+CPSMS", "AT+CPSMS=" + comboBox_CPSMS2.SelectedIndex.ToString() +
                        ",,,\"" + comboBox_CPSMS3.SelectedText.Substring(0, 3) + textBox_CPSMS3.Text + "\",\"" +
                        comboBox_CPSMS4.SelectedText.Substring(0, 3) + textBox_CPSMS4.Text + "\"\r", 300);
                }
                else
                {
                    bC25.encode("AT+CPSMS", "AT+CPSMS=" + comboBox_CPSMS2.SelectedIndex.ToString() + "\r", 300);
                }
                
            }
        }
    }
}
